package com.foreknow.elm.controller;

import com.foreknow.elm.po.Cart;
import com.foreknow.elm.service.CartService;
import com.foreknow.elm.service.Impl.CartServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class CartController {
    public Object listCart(HttpServletRequest request) {
        CartService cs=new CartServiceImpl();
        String userId=request.getParameter("userId");
        int businessId=Integer.parseInt(request.getParameter("businessId"));
        List<Cart>list= cs.listCart(userId,businessId);
        return list;
    }

    public  Object saveCart(HttpServletRequest request) {
        CartService cs=new CartServiceImpl();
        String userId=request.getParameter("userId");
        int businessId=Integer.parseInt(request.getParameter("businessId"));
        int foodId=Integer.parseInt(request.getParameter("foodId"));
        int i= cs.saveCart(userId,businessId,foodId);
        return i;
    }

    public Object updateCart(HttpServletRequest request){
        CartService cs=new CartServiceImpl();
        String userId=request.getParameter("userId");
        int businessId=Integer.parseInt(request.getParameter("businessId"));
        int foodId=Integer.parseInt(request.getParameter("foodId"));
        int quantity=Integer.parseInt(request.getParameter("quantity"));
        int i= cs.updateCart(userId,businessId,foodId,quantity);
        return i;
    }

    public Object removeCart(HttpServletRequest request){
        CartService cs=new CartServiceImpl();
        String userId=request.getParameter("userId");
        int businessId=Integer.parseInt(request.getParameter("businessId"));
        int foodId=Integer.parseInt(request.getParameter("foodId"));
        int i= cs.removeCart(userId,businessId,foodId);
        return i;
    }
}
